<template>
    <aside>
        <!-- 头像部分 -->
        <div class="left">
            <div class="head-portrait">
                <img :src="song.al?.picUrl"/>
            </div>
        </div>
        <div class="right">
            <!-- 歌名 -->
            <section class="song-name">
                <div class="icon"></div>
                <span>{{song.name}}</span>
            </section>
            <!-- 歌手 -->
            <section class="singer">
                歌手：
                <span v-for="(item, index) of song.ar" :key="index">
                    <span class="split" v-if="index>=1">/</span>
                    {{item.name}}
                </span>
            </section>
            <!-- 所属专辑 -->
            <section class="album singer">
                所属专辑：
                <span>{{song.al?.name}}</span>
            </section>
            <!-- 功能区 -->
            <div class="fun">
                <button>
                    <div class="play" @click="play">
                        <el-icon class="play-play"><video-play /></el-icon>
                        <span>播放</span>
                    </div>
                    <el-icon class="add"><plus /></el-icon>
                </button>
                <button>
                    <el-icon><document-add /></el-icon>
                    <span>收藏</span>
                </button>
                <button>
                    <el-icon><share /></el-icon>
                    <span>分享</span>
                </button>
                <button>
                    <el-icon><sort /></el-icon>
                    <span>下载</span>
                </button>
                <button>
                    <el-icon><comment /></el-icon>
                    <span>(1724)</span>
                </button>
            </div>
            <!-- 歌词 -->
            <div class="lyric" :style="'height:' + lyricHeight">
                {{lyric}}
            </div>
            <p class="open" @click="openLyric">
                <span>展开</span>
                <img :src="openLyricIcon" alt="">
            </p>
        </div>
    </aside>
</template>

<script setup>
    import { getCurrentInstance, ref, inject } from "vue";
    import { useRoute } from "vue-router";
    const axios = getCurrentInstance().proxy.$http;

    const route = useRoute();

    const emitter = inject('emitter');

    // 通过歌曲id获取歌曲详情
    let song = ref({});
    (async () => {
        const { data } = await axios({ url: `/song/detail?ids=${route.query.id}` });
        song.value = data.songs[0];
    })();


    // 获取歌词
    const lyric = ref();
    (async () => {
        let { data } = await axios({url: '/lyric?id=' + route.query.id});
        lyric.value = data.lrc.lyric.replace(/\[[0-9]+:[0-9]+.[0-9]+\]/g, '');
    })()


    // 展开功能
    let lyricHeight = ref('260px');
    let bottomPng = require('../../assets/img/bottom.png');
    const topPng = require('../../assets/img/top.png');
    let openLyricIcon = ref(bottomPng);
    const openLyric = () => {
        if(lyricHeight.value == '260px') {
            lyricHeight.value = 'auto';  
            openLyricIcon.value = bottomPng;
        }else {
            lyricHeight.value = '260px';
            openLyricIcon.value = topPng;
        }
    }

    // 播放功能
    const play = async() => {
        emitter.emit('play', route.query.id);
    }

</script>

<style lang='less' scoped>
aside {
    flex-grow: 1;
    display: flex;
    .left {
        width: 206px;
        height: 100%;
        flex-shrink: 0;
        padding-right: 10px;
        .head-portrait {
            width: 100%;
            height: 205px;
            background: url(../../assets/img/coverall.png) no-repeat;
            background-position: -140px -580px;
            position: relative;
            img {
                position: absolute;
                left: 50%;
                top: 50%;
                transform: translate(-50%, -50%);
                width: 130px;
                height: 130px;
                border-radius: 50%;
            }
        }
    }

    .right {
        flex-grow: 1;
        // 歌名
        .song-name {
            .icon {
                width: 54px;
                height: 24px;
                float: left;
                background: url(../../assets/img/icon.png) no-repeat;
                background-position: 0 -463px;
                margin-right: 10px;
            }
            span {
                font-size: 20px;
                font-weight: 500;
            }
            margin-bottom: 10px;
        }

        // 歌手
        .singer {
            font-size: 12px;
            color: #999;
            margin: 10px 0px;
            .split {
                margin-left: 3px;
                color: #999;
            }
            span {
                color: rgb(66, 134, 197);
            }
        }

        // 功能区
        .fun{
            display: flex;
            width: 100%;
            margin-bottom: 20px;
            button{
                margin-top: 10px;
                margin-right: 8px;
                font-size: 13px;
                background-color: #e6e4e4;
                cursor: pointer;
                padding: 4px 5px;
                border: 1px solid rgb(189, 188, 188);
                border-radius: 5px;
                display: flex;
                align-items: center;
                color: rgb(78, 78, 78);
                span{
                    margin-left: 5px;
                }
                &:hover{
                    border: 1px solid rgb(226, 226, 226);
                }
                &:first-child{
                    background-color: rgb(33, 72, 179);
                    color: white;
                    position: relative;
                    border: 1px solid black;
                    .play{
                        display: flex;
                        align-items: center;
                        .play-play{
                            font-size: 17px;
                        }
                        span{
                            margin-top: -2px;
                            margin-right: 20px;
                            padding-right: 8px;
                            margin-left: 2px;
                        }
                        &:hover{
                            color: rgb(46, 175, 104);
                        }
                    }
                    .add{
                        border-left: 1px solid black;
                        padding: 0 5px;
                        position: absolute;
                        height: 100%;
                        right: 0;
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        &:hover{
                            color: white;
                            background-color: rgb(61, 101, 161);
                        }
                    }
                }
            }
            
        }

        // 歌词
        .lyric{
            white-space: pre-line; 
            font-size: 12px;
            line-height: 20px;
            // height: 260px;
            overflow: hidden;
        }
        // 展开
        .open{
            user-select: none;
            span{
                font-size: 13px;
                color: #0c73c2;
                cursor: pointer;
                &:hover{
                    text-decoration: underline;
                }
            }
            img{
                width: 35px;
                height: 35px;
                transform: translate(-10px ,13px);
            }
            
        }
    }
}
</style>

